package com.bw.paper.mvp.view.Fragment.news.Adapter;
import com.bw.paper.entity.ChannelEntity;
import com.bw.paper.utils.LogUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import java.util.Collections;
import cn.cyan.dragrecyclerview.OnItemChangeListener;
public abstract class BaseUserChannelAdapter extends BaseQuickAdapter<ChannelEntity.Values, BaseViewHolder>
        implements OnItemChangeListener {

    public BaseUserChannelAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    public boolean onItemDrag(int position) {
        if (position == 0) {
            return getData().get(position).dragEnable;
        }
        return getData().get(position-1).dragEnable;
    }

    @Override
    public void onItemMoved(int form, int target) {
        if (form < target) {
            // after
            for (int i = form; i < target; i++) {
                Collections.swap(getData(), i, i + 1);
            }
        } else {
            // before
            for (int i = form; i > target; i--) {
                Collections.swap(getData(), i, i - 1);
            }
        }
        notifyItemMoved(form, target);
    }

    @Override
    public boolean onItemDrop(int position) {
        if (position == 0) {
            return getData().get(position).dragEnable;
        }
        return getData().get(position-1).dropEnable;

    }

}